package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sgsc.domain.addresses;
import com.ruoyi.sgsc.service.IaddressesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户地址Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/addresses")
public class addressesController extends BaseController
{
    @Autowired
    private IaddressesService addressesService;

    /**
     * 查询用户地址列表
     */
    @GetMapping("/list")
    public TableDataInfo list(addresses addresses)
    {
        startPage();
        List<addresses> list = addressesService.selectaddressesList(addresses);
        return getDataTable(list);
    }

    /**
     * 导出用户地址列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, addresses addresses)
    {
        List<addresses> list = addressesService.selectaddressesList(addresses);
        ExcelUtil<addresses> util = new ExcelUtil<addresses>(addresses.class);
        util.exportExcel(response, list, "用户地址数据");
    }

    /**
     * 获取用户地址详细信息
     */

    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Long addressId)
    {
        return success(addressesService.selectaddressesByAddressId(addressId));
    }

    /**
     * 根据用户id获取地址列表
     * @param userId
     * @return
     */
    @GetMapping(value = "/addresslist/{userId}")
    public AjaxResult getInfoByUserId(@PathVariable("userId") Long userId)
    {
        return success(addressesService.selectaddressesByUserId(userId));
    }

    /**
     * 新增用户地址
     */

    @PostMapping
    public AjaxResult add(@RequestBody addresses addresses)
    {
        return toAjax(addressesService.insertaddresses(addresses));
    }

    /**
     * 修改用户地址
     */

    @PutMapping
    public AjaxResult edit(@RequestBody addresses addresses)
    {
        return toAjax(addressesService.updateaddresses(addresses));
    }

    /**
     * 删除用户地址
     */

	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Long[] addressIds)
    {
        return toAjax(addressesService.deleteaddressesByAddressIds(addressIds));
    }
}
